package com.itheima.aop;


import org.aspectj.lang.ProceedingJoinPoint;

/*
 * 切面类：提供增强方法的类
 * */
public class LogAop {

    public void before() {
        System.out.println("前置增强");
    }

    public void afterRunning() {
        System.out.println("后置增强");
    }

    public void throwRunning() {
        System.out.println("异常增强");
    }

    public void after() {
        System.out.println("最终增强");
    }

    public Object around(ProceedingJoinPoint point) {
        System.out.println("环绕通知：" + point.getTarget());
        System.out.println("方法名称：" + point.getSignature().getName());
        System.out.println("-------------------");
        Object obj = null;

        try {
            before();
            obj = point.proceed();
            afterRunning();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            throwRunning();
        } finally {
            after();
        }
        return obj;
    }
}
